home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / MultiSkel / MSkelEdit.c next >
Text File  |  1994-02-21  |  3KB  |  192 lines

  1. /*
  2.  * TransSkel multiple-window demonstration: TextEdit module
  3.  *
  4.  * This module handles a simple TextEdit window, in which text may be
  5.  * typed and standard Cut/Copy/Paste/Clear operations may be performed.
  6.  * Undo is not supported, nor is text scrolling.
  7.  *
  8.  * 21 Apr 88 Paul DuBois
  9.  * 29 Jan 89
  10.  * - Conversion for TransSkel 2.0.
  11.  * 12 Jan 91
  12.  * - Conversion for TransSkel 3.0.
  13.  */
  14.  
  15. # include    "TransSkel.h"
  16.  
  17. # include    "MultiSkel.h"
  18.  
  19.  
  20. /* Edit menu item numbers */
  21.  
  22. typedef enum {
  23.     undo = 1,
  24.     /* --- */
  25.     cut = 3,
  26.     copy,
  27.     paste,
  28.     clear
  29. } editItems;
  30.  
  31.  
  32. static TEHandle        teEdit;        /* handle to text window TextEdit record */
  33.  
  34.  
  35. static pascal void
  36. Mouse (Point pt, long t, short mods)
  37. {
  38.     TEClick (pt, (Boolean) ((mods & shiftKey) != 0), teEdit);
  39. }
  40.  
  41.  
  42. static pascal void
  43. Key (short c, short code, short mods)
  44. {
  45.     TEKey (c, teEdit);
  46. }
  47.  
  48.  
  49. /*
  50.  * Update text window.  The update event might be in response to a
  51.  * window resizing.  If so, resize the rects and recalc the linestarts
  52.  * of the text.  To resize the rects, only the right edge of the
  53.  * destRect need be changed (the bottom is not used, and the left and
  54.  * top should not be changed). The viewRect should be sized to the
  55.  * screen.
  56.  */
  57.  
  58. static pascal void
  59. Update (Boolean resized)
  60. {
  61. Rect    r;
  62.  
  63.     r = editWind->portRect;
  64.     EraseRect (&r);
  65.     r.left += 4;
  66.     r.bottom -= 2;
  67.     r.top += 2;
  68.     r.right -= 19;
  69.     if (resized)
  70.     {
  71.         (**teEdit).destRect.right = r.right;
  72.         (**teEdit).viewRect = r;
  73.         TECalText (teEdit);
  74.     }
  75.     DrawGrowBox (editWind);
  76.     TEUpdate (&r, teEdit);
  77. }
  78.  
  79.  
  80. static pascal void
  81. Activate (Boolean active)
  82. {
  83.     DrawGrowBox (editWind);
  84.     if (active)
  85.     {
  86.         TEActivate (teEdit);
  87.         DisableItem (editMenu, undo);
  88.     }
  89.     else
  90.     {
  91.         TEDeactivate (teEdit);
  92.         EnableItem (editMenu, undo);
  93.     }
  94. }
  95.  
  96.  
  97. static pascal void
  98. Clobber (void)
  99. {
  100.     TEDispose (teEdit);
  101.     DisposeWindow (editWind);
  102. }
  103.  
  104.  
  105. static pascal void
  106. Idle (void)
  107. {
  108.     TEIdle (teEdit);    /* blink that cursor! */
  109. }
  110.  
  111.  
  112. void EditWindInit (void)
  113. {
  114. Rect    r;
  115. StringPtr    str;
  116.  
  117.     if (SkelQuery (skelQHasColorQD))
  118.         editWind = GetNewCWindow (editWindRes, nil, (WindowPtr) -1L);
  119.     else
  120.         editWind = GetNewWindow (editWindRes, nil, (WindowPtr) -1L);
  121.     if (editWind == (WindowPtr) nil)
  122.         return;
  123.     (void) SkelWindow (editWind,
  124.                 Mouse,        /* handle mouse-clicks */
  125.                 Key,        /* Key keyclicks */
  126.                 Update,
  127.                 Activate,
  128.                 nil,        /* no close proc */
  129.                 Clobber,    /* disposal proc */
  130.                 Idle,        /* idle proc */
  131.                 true);
  132.  
  133.     TextFont (0);
  134.     TextSize (0);
  135.  
  136.     r = editWind->portRect;
  137.     r.left += 4;
  138.     r.bottom -= 2;
  139.     r.top += 2;
  140.     r.right -= 19;
  141.     teEdit = TENew (&r, &r);
  142.     str = (StringPtr) "\pThis is the text editing window.\r";
  143.     TEInsert (&str[1], (long) str[0], teEdit);
  144. }
  145.  
  146.  
  147. /*
  148.  * Handle Edit menu items for text window
  149.  */
  150.  
  151. pascal void
  152. EditWindEditMenu (short item)
  153. {
  154.     switch (item)
  155.     {
  156.         /*
  157.          * cut selection, put in TE Scrap, clear clipboard and put
  158.          * TE scrap in it
  159.          */
  160.         case cut:
  161.             TECut (teEdit);
  162.             (void) ZeroScrap ();
  163.             (void) TEToScrap ();
  164.             break;
  165.  
  166.         /*
  167.          * copy selection to TE Scrap, clear clipboard and put
  168.          * TE scrap in it
  169.          */
  170.         case copy:
  171.             TECopy (teEdit);
  172.             (void) ZeroScrap ();
  173.             (void) TEToScrap ();
  174.             break;
  175.  
  176.         /*
  177.          * get clipboard into TE scrap, put TE scrap into edit record
  178.          */
  179.         case paste:
  180.             (void) TEFromScrap ();
  181.             TEPaste (teEdit);
  182.             break;
  183.  
  184.         /*
  185.          * delete selection without putting into TE scrap or clipboard
  186.          */
  187.         case clear:
  188.             TEDelete (teEdit);
  189.             break;
  190.     }
  191. }
  192.